package com.culture.config.wrapper;

import com.culture.config.constant.EventSource;
import com.culture.config.constant.EventType;
import com.culture.config.dao.entity.EventLog;
import com.culture.config.model.po.LogPageParam;
import com.culture.config.util.AuthenticationUtil;

import org.apache.commons.lang3.StringUtils;

import lombok.experimental.UtilityClass;

@UtilityClass
public class EventLogWrapper {
	
	public static EventLog wrapEventLogAdd(String eventName, String eventData) {
		EventLog eventLog = new EventLog(eventName,eventData);
		eventLog.setEventType(EventType.EVENT_DEFAULT.id());
		eventLog.setEventSource(EventSource.SOURCE_SYSTEM.getName());
		AuthenticationUtil.setInsertFieldInfo(eventLog);		
		return eventLog;
	}

	public static EventLog wrapLogQuery(LogPageParam param){
		EventLog eventLog = new EventLog();
		eventLog.setEventType(param.getEventType());
		if(StringUtils.isNotBlank(param.getEventName())){
			eventLog.setEventName(param.getEventName());
		}	
		if(StringUtils.isNotBlank(param.getEventSource())){
			eventLog.setEventSource(param.getEventSource());
		}	
		eventLog.setCreateTime(param.getBeginTime());
		eventLog.setEndTime(param.getEndTime());
		return eventLog;
	}
}
